package com.woniuxy.courseweb.controller;


import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import com.woniuxy.core.util.PageInfo;
import com.woniuxy.coursedao.model.TeamSignIn;
import com.woniuxy.coursedao.model.TeamVacate;
import com.woniuxy.coursemodel.dto.TeamSignInDto;
import com.woniuxy.courseservice.service.TeamSignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 团课签到记录表 前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/teamSignIn")
@Api(tags = "团课签到相关接口")
public class TeamSignInController {

    @Resource
    private TeamSignInService teamSignInService;

    /**
     *
     * @param teamCourseId 团课课程id
     * @param token 用户token
     * @return 无
     */
    @ApiOperation("用户签到方法")
    @GetMapping("/signIn")
    public Result<?> signIn(Integer teamCourseId,@RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
        teamSignInService.signIn(teamCourseId,userId);
        return Result.success("用户团课课程签到成功");
    }

    /**
     *
     * @param pageNum 当前页码
     * @param pageSize 每页条数
     * @param token 场馆token
     * @return 无
     */
    @ApiOperation("场馆查看用户签到方法")
    @GetMapping("/byPage")
    public Result<PageInfo<TeamSignInDto>> byPage(Integer pageNum, Integer pageSize, @RequestHeader String token){
        Integer venueId = MyJwtUtil.getVenueIdByKey(token, "venueId");
        PageInfo<TeamSignInDto> pageInfo = teamSignInService.byPage(pageNum,pageSize,venueId);
        return Result.success("分页查看签到成功",pageInfo);
    }

    /**
     *
     * @param teamSignInId 签到信息id
     * @return 无
     */
    @ApiOperation("通过id查看签到方法")
    @GetMapping("/byId")
    public Result<?> byId(Integer teamSignInId){
        TeamSignInDto dto = teamSignInService.byId(teamSignInId);
        return Result.success("通过id查看签到成功",dto);
    }
}

